﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Net;
using System.Windows.Controls;
using DragDropTest;
using FileUploader.Extensions;
using System.Linq;

namespace FileUploader {
    public class Uploader {
        private readonly IView view;
//        private FileUploaderServiceClient service;
        private ObservableCollection<DemoData> demoDataList;

        public Uploader(UploaderControl view){
            this.view = view;
//            service  = new FileUploaderServiceClient();
             demoDataList = DataPersister.ReadData();
//            demoData = DemoData.GetData();
            view.DragableListBox.InnerListBox.ItemsSource = demoDataList;
            //view.DataContext = demoData;
        }

        public void UploadFile(FileInfo file) {
            demoDataList.Add(new DemoData(file));
            view.DragableListBox.InnerListBox.ItemsSource = demoDataList;
            DataPersister.WriteData(demoDataList);

        }

        public void setServerFiles() {
           // view.DragableListBox.ItemsSource = DataPersister.ReadData();

        }

        public void deleteFiles(List<string> fileNames){
            foreach (var fileName in fileNames){
                string name = fileName;
                var item =  demoDataList.Where(i=>i.Name == name).FirstOrDefault();
                demoDataList.Remove(item);
            }
            DataPersister.WriteData(demoDataList);
        }






    }
}
